﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;//引入命名空间

namespace Tank
{
    /// <summary>
    /// Tank成员类(抽象类)
    /// </summary>
    public abstract class TankMember : GameElement
    {
        #region 构造函数
        /// <summary>
        /// 构造函数（无参）
        /// </summary>
        public TankMember()
        {
        }

        /// <summary>
        /// 构造函数（带参）
        /// </summary>
        /// <param name="x">Tank所处的X坐标</param>
        /// <param name="y">Tank所处的Y坐标</param>
        /// <param name="width">Tank的宽度</param>
        /// <param name="height">Tank的高度</param>
        /// <param name="life">Tank的生命</param>
        /// <param name="sp">Tank的速度</param>
        /// <param name="dir">Tank的方向</param>
        public TankMember(int x, int y, int width, int height, int life, int sp, Direction dir)
            : base(x, y, width, height)
        {
            this.Life = life;
            this.Sp = sp;
            this.Dir = dir;
        }
        #endregion

        #region 获取坦克位置、移动、调整移动方向

        /// <summary>
        /// Tank成员的移动方法
        /// </summary>
        public virtual void Move()
        {
            switch (Dir)
            {
                case Direction.U:
                    if (this.Y - Sp < 0)
                    {
                        this.Y = 0;
                    }
                    else
                    {
                        this.Y -= Sp;
                    }
                    break;
                case Direction.D:
                    if (this.Y +Sp > 540)
                    {
                        this.Y = 540;
                    }
                    else
                    {
                        this.Y += Sp;
                    }
                    break;
                case Direction.L:
                    if (this.X - Sp < 0)
                    {
                        this.X = 0;
                    }
                    else
                    {
                        this.X -= Sp;
                    }
                    break;
                case Direction.R:
                    if (this.X + Sp > 720)
                    {
                        this.X = 720;
                    }
                    else
                    {
                        this.X += Sp;
                    }
                    break;
            }
        }

        #endregion

        #region Tank属性

        /// <summary>
        /// 生命
        /// </summary>
        public int Life { get; set; }

        /// <summary>
        /// 速度
        /// </summary>
        public int Sp { get; set; }

        /// <summary>
        /// 方向
        /// </summary>
        public Direction Dir { get; set; }

        #endregion

    }
}
